//
//  myQuestTableViewCell.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/8/6.
//

#import "myQuestTableViewCell.h"
@interface myQuestTableViewCell ()
@property (nonatomic ,strong) UILabel * nameLab;
@property (nonatomic ,strong) UILabel * ydklab;


@property (nonatomic ,strong) UILabel * pondName;
@property (nonatomic ,strong) UILabel * Description;
@property (nonatomic ,strong) UIView * DKbtn;
@property (nonatomic ,strong) UIView * ZJbtn;
@property (nonatomic ,strong) UIView * QXbtn;

@end
@implementation myQuestTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self setupView];
    }
    return self;
}


- (void)setupView{
    
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.clearColor;
    self.userInteractionEnabled = YES;
    self.contentView.userInteractionEnabled = YES;
    
    UIView * backview = [UIView new];
    [self.contentView addSubview:backview];
    backview.backgroundColor = UIColor.whiteColor;
    [DTKTool YJ:kwt(5) andView:backview];
    [backview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(10));
        make.right.offset(kwt(-10));
        make.top.offset(0);
        make.bottom.offset(kwt(-10));
    }];
    
    
    UIImageView * img = kimageView(@"time");
    [backview addSubview:img];
    [img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(12));
        make.width.height.offset(kwt(15));
        make.top.offset(kwt(15));
    }];
    
    UILabel * nameLab = [DTKTool labelWithText:@"" andFont:kCFont(17) andTextColor:KcolorHex(@"#0967FF")];
    self.nameLab = nameLab;
    [backview addSubview:nameLab];
    [nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(33));
        make.centerY.equalTo(img);
    }];
    UILabel * ydklab = [DTKTool labelWithText:@"已打卡" andFont:kFont(16) andTextColor:KcolorHex(@"#0967FF")];
    self.ydklab = ydklab;
    ydklab.textAlignment = NSTextAlignmentRight;
    ydklab.mas_KLS().mas_KYS();
    [backview addSubview:ydklab];
    [ydklab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-12));
        make.left.equalTo(nameLab.mas_right);
        make.centerY.equalTo(img);
    }];
    
    UIView * line = [UIView new];
    line.backgroundColor = KcolorHex(@"#DBDBDB");
    [backview addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(15));
        make.right.offset(kwt(-15));
        make.height.offset(0.5);
        make.top.offset(kwt(41));
    }];
    
    
    UILabel * pondName = [DTKTool labelWithText:@"" andFont:kCFont(17) andTextColor:KcolorHex(@"#222222")];
    self.pondName = pondName;
    [backview addSubview:pondName];
    [pondName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(12));
        make.right.offset(kwt(-12));
        make.top.offset(kwt(54));
    }];
    
    UILabel * description = [DTKTool labelWithText:@"" andFont:kFont(16) andTextColor:KcolorHex(@"#787A79")];
    self.Description = description;
    description.textAlignment = NSTextAlignmentLeft;
    [backview addSubview:description];
    description.numberOfLines = 0;
    [description mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.width.offset(kwt(330));
        make.top.offset(kwt(80));
    }];
    MJWeakSelf
    UIView * DKbtn = [UIView new];
    self.DKbtn= DKbtn;
    DKbtn.clipsToBounds = YES;
    DKbtn.addClickBlock(^{
        if(weakSelf.openDKBlock){
            weakSelf.openDKBlock(weakSelf.model);
        }
    });
    DKbtn.backgroundColor = [UIColor gradientColorWithSize:CGSizeMake(kwt(96), 1) direction:GradientColorDirectionLevel startColor:KcolorHex(@"#427FFF") endColor:KcolorHex(@"#3D5FFF")];
    [DTKTool YJ:kwt(6) andView:DKbtn];
    [backview addSubview:DKbtn];
    [DKbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-12));
        make.width.offset(kwt(96));
        make.height.offset(kwt(36));
        make.bottom.offset(kwt(-15));
    }];
    
    UIImageView * dkimg = kimageView(@"daka");
    [DKbtn addSubview:dkimg];
    [dkimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.left.height.width.offset(kwt(18));
    }];
    
    
    UILabel * dklab = [DTKTool labelWithText:@"打卡" andFont:kFont(16) andTextColor:UIColor.whiteColor];
    [DKbtn addSubview:dklab];
    [dklab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.left.offset(kwt(45));
    }];
    
    
    UIView * ZJbtn = [UIView new];
    self.ZJbtn= ZJbtn;
    ZJbtn.addClickBlock(^{
        if(weakSelf.openZJBlock){
            weakSelf.openZJBlock(weakSelf.model);
        }
    });
    ZJbtn.clipsToBounds = YES;
    ZJbtn.backgroundColor = [UIColor gradientColorWithSize:CGSizeMake(kwt(96), 1) direction:GradientColorDirectionLevel startColor:KcolorHex(@"#427FFF") endColor:KcolorHex(@"#3D5FFF")];
    [DTKTool YJ:kwt(6) andView:ZJbtn];
    [backview addSubview:ZJbtn];
    [ZJbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-12));
        make.width.offset(kwt(96));
        make.height.offset(kwt(36));
        make.bottom.offset(kwt(-15));
    }];
    UILabel * ZJlab = [DTKTool labelWithText:@"转交" andFont:kFont(16) andTextColor:UIColor.whiteColor];
    [ZJbtn addSubview:ZJlab];
    [ZJlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.offset(0);
    }];
    
    UIView * QXbtn = [UIView new];
    self.QXbtn= QXbtn;
    QXbtn.addClickBlock(^{
        if(weakSelf.openQXBlock){
            weakSelf.openQXBlock(weakSelf.model);
        }
    });
    QXbtn.backgroundColor = UIColor.whiteColor;
    [DTKTool YJBK:kwt(6) andView:QXbtn andWidth:0.5 andColor:KcolorHex(@"#C7C7C7")];
    [backview addSubview:QXbtn];
    [QXbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-125));
        make.width.offset(kwt(96));
        make.height.offset(kwt(36));
        make.bottom.offset(kwt(-15));
    }];
    UILabel * QXlab = [DTKTool labelWithText:@"取消" andFont:kFont(16) andTextColor:KcolorHex(@"#5C5C5C")];
    [QXbtn addSubview:QXlab];
    [QXlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.offset(0);
    }];
}
- (void)setModel:(myQuestListModel *)model{
    _model = model;
    self.nameLab.text = [NSString stringWithFormat:@"%@ %@",[model.executeTime componentsSeparatedByString:@" "].lastObject,model.name];
    self.pondName.text = [NSString stringWithFormat:@"%@ %@",model.tissueName,model.pondName];
    self.Description.text = [NSString stringWithFormat:@"任务说明: %@", model.Description];
    if(model.isMy){
        self.DKbtn.hidden = (model.state != 1);
        self.ydklab.hidden = (model.state != 2);
        self.ZJbtn.hidden = YES;
        self.QXbtn.hidden = YES;
    } else {
        if(model.state == 1){
            self.DKbtn.hidden = YES;
            self.ZJbtn.hidden = NO;
            self.QXbtn.hidden = NO;
        } else {
            self.DKbtn.hidden = YES;
            self.ZJbtn.hidden = YES;
            self.QXbtn.hidden = YES;
        }
        self.ydklab.hidden = (model.state != 2);
       
    }
}
@end
